<?php

/**
 * Erra_Fields_Radio - Field radio
 *
 * @package
 * @author Alexis Eric
 * @copyright Copyright (c) 2012 - Erra Prod
 * @version $1.0$
 * @access public
 */
class Erra_Fields_Radio extends Erra_Fields_Base_Field {

    public function __construct($objectId) {
        parent::__construct($objectId);
        $this->setDatabaseType('varchar', 128);
    }

    /**
     * Erra_Fields_Radio::editInstance() - Displays radio buttons with data contained in array passed with 'fill'
     *
     * @param mixed $lang
     * @return
     */
    public function editInstance(Array $extraProperties=null) {
        $res = '<div class="erra-form-field-instance">';
        $res .= $this->outputFieldHeader();

        $counter = 0;
        $res .= '<div ' . $this->getHtmlAttributes($extraProperties) . '>';
        foreach ($this->fieldData as $optionKey => $optionValue) {
            $selected_flag = (!is_null($this->_rawData) && $this->_rawData == $optionKey) ? ' checked ' : '';
            $res .= '<input type="radio" ' . $selected_flag . 'name="' . $this->getHtmlName() . '" id="' . $this->getHtmlId() . '_' . $counter . '" value="' . $optionKey . '" '.$this->getHtmlAttributes($extraProperties).'>' . $optionValue . ' ';
            $counter++;
        }
        $res .= '</div>';
        $res .= '</div>';
        return $res;
    }

    function toHtml($displayParameters = null) {
        return $this->getRawData();
    }

}

?>